<?

/**
  * index.php?dev=<disk device path>
  * Looking for filesystems into 'dev'
  *
**/

require_once(dirname(__FILE__).'/class/Disk.class.php');
require_once(dirname(__FILE__).'/class/FS.class.php');


if (isset($_GET['dev'])){
    // _GET['dev'] exists
    if (Disk::isDisk($_GET['dev'])){
        // _GET['dev'] is a valid disk dev path
        $disk=new Disk($_GET['dev']);
    } else {
        echo "ERROR: ".$_GET['dev']." is not a valid disk device path";
    }
} else {
    echo "ERROR: device parameter doesn't exist";
}

$partitions=$disk->getPartitions();
if (!$partitions){
    $partitions=null;
}

?>

<html>
<head><title>garbirus!</title></head>
<body>
<br \>
<br \>
<h2>New USB device detected!</h2>
<br \>
    Device: <?=$disk->device?> <br \>
    Vendor: <?=$disk->vendor?> <br \>
    Model: <?=$disk->model?> <br \> 
    Partitions: <?=count($partitions)?> <br \>


<h3>Filesystems</h3>
    <ul>
    <?
    if (!is_array($partitions) || count($partitions)==0){
        // No (mountable?) partitions found
        if ($disk->hasFS()){
            // ...but the disk has a Filesystem :D
            $fs=new FS($disk->device);
            echo '<li>'.$disk->device.': '.$fs->label.' ('.number_format($fs->size/1024/1024/1024, 2).' GB) [<a href="analyze.php?dev='.$disk->device.'">analyze</a>] </li>';
        } else {
            echo "ERROR: No filesystem found";
        }
    } else {
        foreach ($partitions as $partition){
            $fs=new FS($partition);
    ?>
            <li><?=$partition?>: <?=$fs->label?> (<?=number_format($fs->size/1024/1024/1024, 2)?> GB) [<a href="analyze.php?dev=<?=$partition?>">analyze</a>] </li>
   <?
        }
    }
    ?>
    </ul>
</body>
</html>
